/**
 * wdk.com Inc.
 * Copyright (c) 2004-2019 All Rights Reserved.
 */
package com.da.javatest.util;

import java.util.ArrayList;
import java.util.List;

/**
 * 对象类转换工具
 */
public abstract class AbstractConvert<T1, T2> {

    /**
     * 业务领域对象转换工具
     */
    protected abstract T1 convert(T2 t2);

    /**
     * 数据转换
     */
    protected List<T1> convert(List<T2> sourceList) {
        if (sourceList == null) {
            return null;
        }

        List<T1> targetList = new ArrayList<>();
        for (T2 t2 : sourceList) {
            T1 t1 = convert(t2);
            if (t1 == null) {
                continue;
            }
            targetList.add(t1);
        }
        return targetList;
    }
}